<?php

if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

/**
 * Check whether the string is email
 *
 * @param
 *        	string	checked string
 * @return boolean
 */
if (! function_exists ( 'is_email' )) {
	function is_email($str) {
		if ($str == null)
			return false;
		
		return (preg_match ( "/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/", $str ));
	}
}

/**
 * Check whether the string is phone
 * number
 *
 * @param
 *        	string	checked string
 * @return boolean
 */
if (! function_exists ( 'is_phone_no' )) {
	function is_phone_no($str) {
		if ($str == null || ! is_numeric ( $str ) || strlen ( $str ) != 11)
			return false;
		
		return true;
	}
}

/**
 * Check whether the string is phone
 * number
 *
 * @param
 *        	Str string
 * @param
 *        	Length int
 * @return string
 */
if (! function_exists ( 'sub_utf_string' )) {
	function sub_utf_string($Str, $Length) {
		global $s;
		$i = 0;
		$l = 0;
		$ll = strlen ( $Str );
		$utf_l = utf8_strlen ( $Str );
		if ($utf_l <= $Length)
			return $Str;
		$s = $Str;
		$f = true;
		
		while ( $i <= $ll ) {
			if (ord ( $Str {$i} ) < 0x80) {
				$l ++;
				$i ++;
			} else if (ord ( $Str {$i} ) < 0xe0) {
				$l ++;
				$i += 2;
			} else if (ord ( $Str {$i} ) < 0xf0) {
				$l += 1;
				$i += 3;
			} else if (ord ( $Str {$i} ) < 0xf8) {
				$l += 1;
				$i += 4;
			} else if (ord ( $Str {$i} ) < 0xfc) {
				$l += 1;
				$i += 5;
			} else if (ord ( $Str {$i} ) < 0xfe) {
				$l += 1;
				$i += 6;
			}
			
			if (($l >= $Length - 1) && $f) {
				$s = substr ( $Str, 0, $i );
				$f = false;
			}
			
			if (($l > $Length) && ($i < $ll)) {
				$s = $s . '...';
				break; // 如果进行了截取，字符串末尾加省略符号“...”
			}
		}
		return $s;
	}
}
/**
 * get lenght as utf8
 *
 * @param string $string        	
 * @return number
 */
if (! function_exists ( 'utf8_strlen' )) {
	function utf8_strlen($string = null) {
		preg_match_all ( '/./us', $string, $match );
		return count ( $match [0] );
	}
}

if (! function_exists ( 'str_replace_escape' )) {
	function str_replace_escape($a, $str) {
		return str_replace('\\'.$a,$a,$str);
	}
}

if(! function_exists('get_ip_name')){
        function get_ip_name($ip){
                switch ($ip){
                        case '127.0.0.1':     return "Xiaohua Pan";
                        case '192.168.1.18':  return "JingXi Zhang";
                        case '192.168.1.147': return "Zihui Mao";
                        case '192.168.1.101': return "Wei Wang";
                        case '192.168.1.120': return "Shengshan Jing";
                        case '192.168.1.134': return "Xianlong Yi";
                        case '192.168.1.109': return "Xiaoyu Ruan";
                        default: return "Anonymous";
                }
        }
}

